//
//  DiseaseDetailController.m
//  KYProject
//
//  Created by Roman on 16/12/23.
//  Copyright © 2016年 Roman. All rights reserved.
//

#import "DiseaseDetailController.h"
#import "NetWorkManager.h"
#import "Disease.h"

@interface DiseaseDetailController ()<UITableViewDataSource,UITableViewDelegate>

@property(strong, nonatomic) UISearchController *searchController;
@property (strong, nonatomic)NSMutableArray  *searchList;//满足搜索条件的数组
//病例类型
@property(nonatomic,assign)int ciId;
@property(nonatomic,assign)int page;
@property(nonatomic,strong)NSArray *xiFenArray;

@end
static NSString *cellID = @"Cell";
@implementation DiseaseDetailController
- (void)LoadDataWith:(NSInteger)ciId Page:(int)page
{
    self.xiFenArray = nil;
    self.ciId = (int)ciId;
   
    self.page = page;
    
}

//数据加载
-(void)loadDataXiFenArray
{
    self.xiFenArray = [[NSArray alloc]init];
    [[NetWorkManager sharedManage] loadDiseaseSubWithCi_id:_ciId page:_page successBlock:^(NSArray *dtoArray) {
        self.xiFenArray = dtoArray;
        [self.tableView reloadData];
    } errorBlock:^(NSString *error) {
    }];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    //  [self setUpLeftButtonItem];
    //行高
    self.tableView.rowHeight = 50;
    //去掉分隔线
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    //可穿透
    self.navigationController.navigationBar.translucent = YES;
    //数据加载
    if (!self.xiFenArray) {
        [self loadDataXiFenArray];
        //搜索导航栏
       // [self setSearchControllerView];
    }
    self.tableView.tableFooterView = [[UIView alloc]init];
    [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:cellID];
    
}

#pragma mark - Table view data source
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    //控制器使用的时候，就是点击了搜索框的时候
    if (self.searchController.active) {
        return self.searchList.count;
    }
    return self.xiFenArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID forIndexPath:indexPath];
    
    //搜索控制数据
    if (self.searchController.active)
    {
        Disease *mondel = self.searchList[indexPath.row];
        cell.textLabel.text = mondel.ci3_name;
        return cell;
    }
    //细分
    Disease *mondel = self.xiFenArray[indexPath.row];
    cell.textLabel.text = mondel.ci3_name;
    return cell;
}

//cell的选中
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    //获取数据
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    NSString * titles = cell.textLabel.text;
    if (self.cellTextblock) {
        //细分病例数据传递
        _cellTextblock(titles,0);
    }
    //发送通知 给疾病详情页面赋值
    [[NSNotificationCenter defaultCenter]postNotificationName:@"DiseaseDetail" object:cell.textLabel.text userInfo:nil];
    [self.navigationController popViewControllerAnimated:YES];
    
}


@end
